Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS button onClick clean up #2282

Merged
merged 3 commits into from
Sep 4, 2019
Merged

Conversation

thompsongl
Copy link
Contributor

@thompsongl thompsongl commented Sep 4, 2019

Summary

TypeScript clean up related to a button component using NoArgCallback<void> for onClick. It instead needs to allow for an event param and discriminate between a and button element renders.

The component was used as the base for 2 other components, so they also needed to be updated.

Checklist

- [ ] Checked in dark mode
- [ ] Checked in mobile
- [ ] Checked in IE11 and Firefox
- [ ] Props have proper autodocs
- [ ] Added documentation examples
- [ ] Added or updated jest tests
- [ ] Checked for breaking changes and labeled appropriately
- [ ] Checked for accessibility including keyboard-only and screenreader modes

  • A changelog entry exists and is marked appropriately

@thompsongl
Copy link
Contributor Author

I'm considering adding 2 generics to common.ts to help with this sort of thing, but they can't be used in all cases because of some one-off Omit, etc. in other button-like components:

export type PropsForAnchor<T, P = {}> = T &
  AnchorHTMLAttributes<HTMLAnchorElement> & {
    href?: string;
    onClick?: MouseEventHandler<HTMLAnchorElement>;
  } & P;

export type PropsForButton<T, P = {}> = T &
  ButtonHTMLAttributes<HTMLButtonElement> & {
    onClick?: MouseEventHandler<HTMLButtonElement>;
  } & P;

Worth it?

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM, thanks!!

@chandlerprall
Copy link
Contributor

I like the generics idea, helps solidify the solution, prevents mistakes, and we could expand the type to take a 3rd argument of props to omit (hoping to avoid the one-off solutions)

@thompsongl thompsongl merged commit 7cc470f into elastic:master Sep 4, 2019
thompsongl added a commit to thompsongl/eui that referenced this pull request Sep 10, 2019
* button onclick clean up

* clickable generics

* CL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants